package com.abc.common.springmvc.velocity;

import com.abc.common.web.url.WebUrl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.view.AbstractUrlBasedView;
import org.springframework.web.servlet.view.velocity.VelocityLayoutView;
import org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver;

import java.util.Map;

/**
 * Created by xuexue on 2014/4/13.
 */
public class VelocityToolsMapViewResolver extends VelocityLayoutViewResolver{
    private Map<String, Object> velocityTools;
    private Map<String, WebUrl> velocityUrl;

    /**
     * Requires VelocityLayoutView.
     * @see VelocityLayoutView
     */
    @Override
    protected Class requiredViewClass() {
        return VelocityToolsMapView.class;
    }

    @Override
    protected AbstractUrlBasedView buildView(String viewName) throws Exception {
        VelocityToolsMapView view = (VelocityToolsMapView) super.buildView(viewName);
        // Use not-null checks to preserve VelocityLayoutView's defaults.
        if (this.velocityTools != null) {
            view.setVelocityTools(this.velocityTools);
        }
        if (this.velocityUrl != null) {
            view.setVelocityUrl(this.velocityUrl);
        }
        return view;
    }

    public void setVelocityTools(Map<String, Object> velocityTools) {
        this.velocityTools = velocityTools;
    }

    public void setVelocityUrl(Map<String, WebUrl> velocityUrl) {
        this.velocityUrl = velocityUrl;
    }
}
